﻿using System.Collections.Generic;
using System.Web.Http.ModelBinding;
namespace Sustainalytics.Events.Service.Errors
{
    public class ErrorModel
    {
        public int ErrorStatusCode { get; set; }

        public string ErrorMessage { get; set; }

    }

    public class ModelStateErrorsDto : ErrorModel
    {
        public ModelStateErrorsDto(ModelStateDictionary modelState, int errorCode)
        {
            this.ErrorStatusCode = errorCode;
            this.Errors = new Dictionary<string, IEnumerable<string>>();

            foreach (var item in modelState)
            {
                var itemErrors = new List<string>();
                foreach (var error in item.Value.Errors)
                {
                    itemErrors.Add(error.ErrorMessage);
                }
                Errors.Add(item.Key, itemErrors);
            }
        }


        public IDictionary<string, IEnumerable<string>> Errors { get; set; }
    }


    public class ErrorModel<T> : ErrorModel
    {
        public T Details { get; set; }
    }
}
